/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.N100;
import queenb.web.store.V100Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.ContextUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Hung.Ngo
 */
public class V100Controller extends QueenbController{
    private int pv100;
    private List<SelectItem> listComboV100 = new ArrayList<SelectItem>();
    private int fv050;
    private String vv101;
    private String vv102;
    private String vv103;
    private String vv104;
    private String vv105;
    private String vv106;
    private String vv107;
    private String vv108;
    private String vv109;
     private String vv110;
      private String vv111;
    private Date vd112;
    private Date vd113;
    
    private String vv114;
    private String vv115;
    private String vv116;
    private String vv117;
    private String vv118;
    private String vv119;
    private String vv120;
    private String vv121;
    private String vv122;
    private V100Store store ;
    private Date vd123;
    private Date vd124;
    
    private List<N100> listLoadData;
    
    
    
    public V100Controller(){
        store = new V100Store();
        Object action = getRequest().getParameter("action");
        if(action!=null){
            if(action.equals("addpersonalforTour")){
                Object Ofv050 = getRequest().getParameter("pv050");
                if(Ofv050!=null){
                    fv050 = Util.parseInt(Ofv050);
                }
            }else  if(action.equals("addGroup")){
                Object Ofv050 = getRequest().getParameter("pv100");
                if(Ofv050!=null){
                    pv100 = Util.parseInt(Ofv050);
                    listLoadData = getVCURPKS_LISTOFTABV100(pv100);
                    SessionProvider.setSessionMapValue("LISTV100TOUR",listLoadData);
                }
            }
        }
       
        
    }
    
//    public void changeGroup(ActionEvent ev){
//        try {
//            System.out.println("----------------"+pv100);
//            SessionProvider.setSessionMapValue("IDCHANGEGROUPFORLOADDATA", pv100);
//        } catch (Exception e) {
//        }
//    }
    
    public List<N100> getVCURPKS_LISTOFTABV100(int PV100P){
        try {
       
            List<N100> listV100 = store.VCURPKS_LISTOFTABV100(PV100P,getLogin().getModule(), getLogin().getCompanyNo(), null);
            return listV100;
        } catch (Exception e) {
            return null;
        }
    }
    
    public void saveV100() throws SQLException, InstantiationException, ParseException{
        try {
            String date = ContextUtil.getRequestParameter("leavedate1");
            if (!date.equals("")) {
                setVd112(Util.parseDate(date, "dd/MM/yyyy"));
            } else {
                setVd112(null);
            }

            date = ContextUtil.getRequestParameter("leavedate2");
            if (!date.equals("")) {
                setVd113(Util.parseDate(date, "dd/MM/yyyy"));
            } else {
                setVd113(null);
            }
             date = ContextUtil.getRequestParameter("leavedate3");
            if (!date.equals("")) {
                setVd123(Util.parseDate(date, "dd/MM/yyyy"));
            } else {
                setVd123(null);
            }

            date = ContextUtil.getRequestParameter("leavedate4");
            if (!date.equals("")) {
                setVd124(Util.parseDate(date, "dd/MM/yyyy"));
            } else {
                setVd124(null);
            }
            

            int count = store.updateV100(pv100,fv050, getLogin().getModule(),getLogin().getCompanyNo(), vv101,vv102,vv103,vv104, vv105, vv106, vv107,vv108,vv109, vv110, vv111,Util.toSQLDate(vd112),Util.toSQLDate(vd113),
                    vv114, vv115, vv116, vv117, vv118, vv119, vv120, vv121,vv122,Util.toSQLDate(vd123),Util.toSQLDate(vd124),getLogin().getUserName());
            if (count != 0) {
             
                sendRedirectUrlTab("customer4tour.jsp?status=T&pv050=" + fv050);
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                sendRedirectUrlTab("customer4tour.jsp?status=T&pv050=" + fv050);

                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
           
        } catch (IllegalAccessException ex) {
            Logger.getLogger(V100Controller.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @return the fv050
     */
    public int getFv050() {
        return fv050;
    }

    /**
     * @param fv050 the fv050 to set
     */
    public void setFv050(int fv050) {
        this.fv050 = fv050;
    }

    /**
     * @return the vv101
     */
    public String getVv101() {
        return vv101;
    }

    /**
     * @param vv101 the vv101 to set
     */
    public void setVv101(String vv101) {
        this.vv101 = vv101;
    }

    /**
     * @return the vv102
     */
    public String getVv102() {
        return vv102;
    }

    /**
     * @param vv102 the vv102 to set
     */
    public void setVv102(String vv102) {
        this.vv102 = vv102;
    }

    /**
     * @return the vv103
     */
    public String getVv103() {
        return vv103;
    }

    /**
     * @param vv103 the vv103 to set
     */
    public void setVv103(String vv103) {
        this.vv103 = vv103;
    }

    /**
     * @return the vv104
     */
    public String getVv104() {
        return vv104;
    }

    /**
     * @param vv104 the vv104 to set
     */
    public void setVv104(String vv104) {
        this.vv104 = vv104;
    }

    /**
     * @return the vv105
     */
    public String getVv105() {
        return vv105;
    }

    /**
     * @param vv105 the vv105 to set
     */
    public void setVv105(String vv105) {
        this.vv105 = vv105;
    }

    /**
     * @return the vv106
     */
    public String getVv106() {
        return vv106;
    }

    /**
     * @param vv106 the vv106 to set
     */
    public void setVv106(String vv106) {
        this.vv106 = vv106;
    }

    /**
     * @return the vv107
     */
    public String getVv107() {
        return vv107;
    }

    /**
     * @param vv107 the vv107 to set
     */
    public void setVv107(String vv107) {
        this.vv107 = vv107;
    }

    /**
     * @return the vv108
     */
    public String getVv108() {
        return vv108;
    }

    /**
     * @param vv108 the vv108 to set
     */
    public void setVv108(String vv108) {
        this.vv108 = vv108;
    }

    /**
     * @return the vv109
     */
    public String getVv109() {
        return vv109;
    }

    /**
     * @param vv109 the vv109 to set
     */
    public void setVv109(String vv109) {
        this.vv109 = vv109;
    }

    /**
     * @return the vv110
     */
    public String getVv110() {
        return vv110;
    }

    /**
     * @param vv110 the vv110 to set
     */
    public void setVv110(String vv110) {
        this.vv110 = vv110;
    }

    /**
     * @return the vv111
     */
    public String getVv111() {
        return vv111;
    }

    /**
     * @param vv111 the vv111 to set
     */
    public void setVv111(String vv111) {
        this.vv111 = vv111;
    }

    /**
     * @return the vd112
     */
    public Date getVd112() {
        return vd112;
    }

    /**
     * @param vd112 the vd112 to set
     */
    public void setVd112(Date vd112) {
        this.vd112 = vd112;
    }

    /**
     * @return the vd113
     */
    public Date getVd113() {
        return vd113;
    }

    /**
     * @param vd113 the vd113 to set
     */
    public void setVd113(Date vd113) {
        this.vd113 = vd113;
    }

    /**
     * @return the vv114
     */
    public String getVv114() {
        return vv114;
    }

    /**
     * @param vv114 the vv114 to set
     */
    public void setVv114(String vv114) {
        this.vv114 = vv114;
    }

    /**
     * @return the vv115
     */
    public String getVv115() {
        return vv115;
    }

    /**
     * @param vv115 the vv115 to set
     */
    public void setVv115(String vv115) {
        this.vv115 = vv115;
    }

    /**
     * @return the vv116
     */
    public String getVv116() {
        return vv116;
    }

    /**
     * @param vv116 the vv116 to set
     */
    public void setVv116(String vv116) {
        this.vv116 = vv116;
    }

    /**
     * @return the vv117
     */
    public String getVv117() {
        return vv117;
    }

    /**
     * @param vv117 the vv117 to set
     */
    public void setVv117(String vv117) {
        this.vv117 = vv117;
    }

    /**
     * @return the vv118
     */
    public String getVv118() {
        return vv118;
    }

    /**
     * @param vv118 the vv118 to set
     */
    public void setVv118(String vv118) {
        this.vv118 = vv118;
    }

    /**
     * @return the vv119
     */
    public String getVv119() {
        return vv119;
    }

    /**
     * @param vv119 the vv119 to set
     */
    public void setVv119(String vv119) {
        this.vv119 = vv119;
    }

    /**
     * @return the vv120
     */
    public String getVv120() {
        return vv120;
    }

    /**
     * @param vv120 the vv120 to set
     */
    public void setVv120(String vv120) {
        this.vv120 = vv120;
    }

    /**
     * @return the vv121
     */
    public String getVv121() {
        return vv121;
    }

    /**
     * @param vv121 the vv121 to set
     */
    public void setVv121(String vv121) {
        this.vv121 = vv121;
    }

    /**
     * @return the vv122
     */
    public String getVv122() {
        return vv122;
    }

    /**
     * @param vv122 the vv122 to set
     */
    public void setVv122(String vv122) {
        this.vv122 = vv122;
    }

    /**
     * @return the vd123
     */
    public Date getVd123() {
        return vd123;
    }

    /**
     * @param vd123 the vd123 to set
     */
    public void setVd123(Date vd123) {
        this.vd123 = vd123;
    }

    /**
     * @return the vd124
     */
    public Date getVd124() {
        return vd124;
    }

    /**
     * @param vd124 the vd124 to set
     */
    public void setVd124(Date vd124) {
        this.vd124 = vd124;
    }

    /**
     * @return the pv100
     */
    public int getPv100() {
        return pv100;
    }

    /**
     * @param pv100 the pv100 to set
     */
    public void setPv100(int pv100) {
        this.pv100 = pv100;
    }

    /**
     * @return the listComboV100
     */
    public List<SelectItem> getListComboV100() {
        ComboboxUtil combo = new ComboboxUtil();
        
        listComboV100 = combo.getListComboV100();
        return listComboV100;
    }

    /**
     * @param listComboV100 the listComboV100 to set
     */
    public void setListComboV100(List<SelectItem> listComboV100) {
        this.listComboV100 = listComboV100;
    }

    /**
     * @return the listLoadData
     */
    public List<N100> getListLoadData() {
//          if( SessionProvider.getSessionMapValue("IDCHANGEGROUPFORLOADDATA")!=null){
//                pv100 = Util.parseInt( SessionProvider.getSessionMapValue("IDCHANGEGROUPFORLOADDATA"));
//            }
//         if(pv100!=0){
//             listLoadData = getVCURPKS_LISTOFTABV100(pv100);
//         }
        return listLoadData;
    }

    /**
     * @param listLoadData the listLoadData to set
     */
    public void setListLoadData(List<N100> listLoadData) {
        this.listLoadData = listLoadData;
    }
}
